
var IbwAssistant = Class.create(AbstractModule, {

//BsaAssistant.prototype.setup = function() {
//	$("header").innerHTML = this.title;

setupWidgets: function() {

		//About
		this.controller.setupWidget(Mojo.Menu.appMenu, {
			omitDefaultItems: true
		}, {
			visible: true,
			items: [
      		Mojo.Menu.editItem,
			{ label: "Disclaimer", command: "do-disclaimer" },					
				{ label: "License", command: "do-license" },
				{ label: "Help", command: "do-help" }
			]
		});

	this.toggleunit =
	{
		modelProperty: 'togglestate',
		trueLabel: 'SI',
	falseLabel: 'US'
	};
	this.togglemodel = {
		togglestate: true
	};
	this.controller.setupWidget("unitField", this.toggleunit, this.togglemodel);
	this.controller.listen("unitField", Mojo.Event.propertyChanged, this.unitChanged.bindAsEventListener(this));

	
	this.controller.setupWidget("sex", {
			label: "Sex",
			choices: [
				{ label: "Male", value: 1},
				{ label: "Female", value: 0}
			]
		}, this.sexModel = {
			value: 1
		});

	this.controller.setupWidget("heightField", {
		charsAllow: isValidFPNumber,
		modifierState: Mojo.Widget.numLock
	}, {
	value: height
	});

	
},

unitChanged: function() {
//change unit display in bmi scene
var unitchoice = this.togglemodel.togglestate;

if (!unitchoice){
$("heightUnit").update("<span class=\"si\">(in)</span>");
}

if (unitchoice){
$("heightUnit").update("<span class=\"si\">(cm)</span>");
}

},


	calculate: function() {
	var result = ibwcalc(this.togglemodel.togglestate, this.sexModel.value, $("heightField").mojo.getValue());
	height=result.height;
	var lbs=result.ibw*2.2046;
	lbs=Math.round(lbs*100)/100;
	var interp="";
	
	if (result.ibw>0){	
	interp= ("The IBW is " + result.ibw +" kg or " + lbs + " lbs");
	}
	
	if (result.ibw==0){	
	interp = ("This IBW module is not applicable for height under 5 feet (60 inches)");
	}
	
	return interp;
	
	}
});





